<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
{% load tags %}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>{% block title %}{{ group.group_name }} Connect{% endblock %}</title>
{% block extra_css %}{% endblock %}

    <link href="/static_media/StartGroup/css/group.css" media="screen, projection" rel="stylesheet" type="text/css"/>    
{% block extra_js %}
    <script src="/static_media/contifyuser/js/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
	$(document).ready(function(){$("a.delEvent").click(function(){
	    var eveid = $(this).attr('eveid');
            var webaddr = $("#hiddenWebaddr").html();
	    jQuery.ajax({
	      url: '/connectpeople/group/' + webaddr +'/',
	      type: 'POST',
	      data: {'eveid':eveid},
	      dataType: 'json',
	      success: function(json){
                document.getElementById(eveid).style.display="none";
	    },
	      error: function(xhr, ajaxOptions, thrownError){
		alert("An Error Has Occurred. Please try again.");
	      }
	    });
	});
	});
	
	 $(document).ready(function(){$("input.postComment").click(function(e){
	    var comm_id = "#" + $(this).attr('activity_id');
            var comment_div = $(comm_id);
	    jQuery.ajax({
	      url: '/connectpeople/home/',
	      type: 'POST',
	      data: {'action': 'NEW_DISCUSSION_ACTIVITY_COMMENT_POSTED', 'comment': comment_div.val(), 'acti_id': $(this).attr('activity_id')},
	      dataType: 'json',
	      success: function(json){
		alert("success");
	    },
	      error: function(xhr, ajaxOptions, thrownError){
		alert("An Error Has Occurred. Please try again.");
	      }
	    });
	  });
	  });
         
        // Other Activity Ajax method
        $(document).ready(function(){$("a.other_act_like").click(function(e){
	    var comm_id = "#" + $(this).attr('activity_id');
            var comment_div = $(comm_id);
	    jQuery.ajax({
	      url: '/connectpeople/home/',
	      type: 'POST',
	      data: {'action': 'NEW_DISCUSSION_ACTIVITY_LIKED', 'type': 'LIKE', 'value': 1, 'index': $(this).attr('id')},
	      dataType: 'json',
	      success: function(json){
		alert("success");
	    },
	      error: function(xhr, ajaxOptions, thrownError){
		alert("An Error Has Occurred. Please try again.");
	      }
	    });
	  });
	  });	

    </script>
{% endblock %}
</head>

<body>
    {% block portraitUpload %}
    {% if permission == "Owner" or permission == "Board Member" %}
    <div>
	<form method="POST" id="group_portrait_form" action="/connectpeople/group/{{ group.group_web_address }}/"  enctype="multipart/form-data">
	    <input type="hidden" id="portrait_action" name="action" value="GROUP_PORTRAIT_UPLOAD"/>
	    <div>
		<div><span><strong>Upload Portrait </strong></span></div>
		<div>{{ portrait_form.image }}</div>
	    </div>
	    <div>
		<input type="submit" value="Upload"  name='uploadPortrait'/>
	    </div>	    
	</form>
    </div>
    {% endif %}
    {% endblock %}
    {% block groupHeader %}
    <div id="hiddenWebaddr" style="display:none">{{ group.group_web_address }}</div>
    <div class="groupHeaderContainer">
        <div class="nobreak">            
            <div><a style="text-decoration: none;" href="/connectpeople/group/{{ group.group_web_address }}"><span class="groupHeaderTitle"><strong>{{ group.group_name }}</strong></span></a></div>
            <div class="groupHeaderTagLine">{{ group.group_tagline }}</div>
        </div>
        
        <div id="container">
            <div class="nobreak">
                
            </div>            
            <div class="nobreak">
                <!--<li><a href="{% url contifyuser.views.viewprofile %}">Profile</a></li>-->
                <div>
		    <span class=""><a href="{% url StartGroup.views.startNewGroupForm %}">Start New Group</a></span>
		    {% if permission != 'Non Member' %}
			<a href="/connectpeople/{{ group.group_web_address }}/discussion/new">Start New Discussion</a>
		    {% endif%}
		    <a href="/connectpeople/{{ group.group_web_address }}/discussion/portal">Discussions</a>
		    <a href="/connectpeople/{{ group.group_web_address }}/groupinfo/info">Group Information</a>
		    <a href="/connectpeople/{{ group.group_web_address }}/polls">Polls</a>
		    <a href="/connectpeople/{{ group.group_web_address }}/ideas/view">Ideas</a>
		</div>
		<div>
		    {% if permission == "Owner" or permission == "Board Member" %}
			<a href="/connectpeople/{{ group.group_web_address }}/ManageMoney/home/">Manage Money</a>
		    {% endif %}
		    {% if permission == "Owner" or permission == "Board Member" or permission == "Assistant Board Member" %}
			<a href="/connectpeople/{{ group.group_web_address }}/album/upload">Album Upload</a>
		    {% endif%}
		    <a href="/connectpeople/photologuegallery/">Albums</a>
		    {% if permission == "Owner" or permission == "Board Member" or permission == "Assistant Board Member" %}
			<a href="/connectpeople/{{ group.group_web_address }}/announcement/view">Announcements</a>
		    {% endif%}
		    {% if permission == "Owner" or permission == "Board Member" or permission == "Assistant Board Member" %}
			<a href="/connectpeople/{{ group.group_web_address }}/docs/view">Files</a>
		    {% endif%}		    
		    {% if permission == 'Non Member' %}
			<a href="/connectpeople/{{ group.group_web_address }}/groupMembers/joined">Join</a>
		    {% else %}
			<a href="/connectpeople/{{ group.group_web_address }}/groupMembers/leave">Leave Group</a>
		    {% endif%}
		</div>
            </div>
        </div>
    </div>
    {% endblock %}
    {% block announcements %}
    {% if announcements %}
    <div>
	<marquee behavior="scroll" direction="left">
	    {% for each in announcements %}
		<span class="eachAnnounce">
		    <strong>{{ each.title }}</strong>
		</span>
	    {% endfor %}
	</marquee>
    </div>
    {% endif %}
    {% endblock %}    
    {% block leftMenu %}
    <div class="groupHomeLeftMenu nobreak">
	<div class="portraitSection">
	    <div>
		{{ portrait.get_avatar_url|portrait_img }}
	    </div>
	    <div>
		{{ permission }}
	    </div>
	</div>
    </div>
    {% endblock %}
{% block content %}
    {% if permission != "Non Member"%}
    <div class="nobreak activitiy">
	<div class="nobreak clearbreak activityStartLine">
	    &nbsp;
	</div>                    
	{% for each_activity in activity_dict %}
	<div class="nobreak clearbreak eachActivitySection">
	    <div class="nobreak clearbreak eachActivity">
		<div class="nobreak eachActivityLeft">
		    &nbsp;
		</div>
		<div class="nobreak eachActivityMiddle">
		    <div id="activity_{{ each_activity.0 }}">
			<strong>{{each_activity.2}}</strong>
		    </div>
		    <div class="nobreak clearbreak likeLink otherActivityMargin" id="other_act">
			<a href="#" id="other_act_{{ each_activity.0 }}" class="other_act_like">like</a>
		    </div>
		    {% if each_activity.6 %}
			<div class="nobreak clearbreak likeLink otherActivityMargin">
			    <div class="nobreak">
				Liked by: 
			    </div>
			{% for other_activity in each_activity.6%}
			    <div class="nobreak" id="other_activity_{{ other_activity.0 }}">
				{% if forloop.counter > 1%}
				    , 
				{% endif %}
				{{ other_activity.4|user_profile }}
			    </div>                                  
			{% endfor %}
			</div>
		    {% endif %}
		    <div class="nobreak clearbreak otherActivityMargin">                           
			{% if each_activity.5 %}
			    {% for comment in each_activity.5%}                                        
				<div class="nobreak clearbreak activitySubSection" id="comment_{{ comment.0 }}">
				    <div class="nobreak clearbreak">
					{{ comment.3|user_profile }}: <strong>{{ comment.2 }}</strong>
				    </div>
				</div>                                  
				<div class="nobreak clearbreak likeLink" id="comm_other_act">                                                
				    <div class="nobreak">
					{{ comment.1 }} 
				    </div>
				    <div class="nobreak otherActivityMargin">
					<a href="#" id="comm_other_act_{{ comment.0 }}" class="other_act_like">like</a>
				    </div>
				    </div>
				{% if comment.4 %}
				    <div class="nobreak clearbreak likeLink">
					<div class="nobreak">
					    Liked by: 
					</div>                                            
				    {% for comm_other_activity in comment.4 %}
					<div class="nobreak" id="comment_other_activity_{{ comm_other_activity.0 }}">
					    {% if forloop.counter > 1%}
						, 
					    {% endif %}
					    {{ comm_other_activity.4|user_profile }}
					</div>                       
				    {% endfor %}
				    </div>
				{% endif %}                                    
			    {% endfor %}
			{% endif %}
			<div class="nobreak clearbreak activitySubSection">
			    <div class="nobreak clearbreak">
				<textarea id="{{ each_activity.0 }}" class="comment commentArea"></textarea>
			    </div>
			    <div class="nobreak clearbreak">
				<input id="submit_comment" activity_id="{{ each_activity.0 }}" type="button" value="Comment" class="postComment"/>                                                              
			    </div>
			</div>
		    </div>
		</div>
		<div class="nobreak eachActivityRight">
		    <div class="nobreak clearbreak">
			{{ each_activity.4|user_profile }}
		    </div>
		    <div class="nobreak clearbreak">
			{% if each_activity.3 = 'New Discussion' %}
			    New Discussion
			{% endif %}
			{% if each_activity.3 = 'Create Poll' %}
			    New Poll
			{% endif %}                        
			{% if each_activity.3 = 'Poll Voted' %}
			    New Vote
			{% endif %}
			{% if each_activity.3 = 'Create Event' %}
			    New Event
			{% endif %}
			{% if each_activity.3 = 'RSVP to Event' %}
			    New RSVP
			{% endif %}
			{% if each_activity.3 = 'Comment on Event' %}
			    New Comment to Event
			{% endif %}
			{% if each_activity.3 = 'Group Information Update' %}
			    Group Information Updated
			{% endif %}
			{% if each_activity.3 = 'Comment on Discussion' %}
			    New Comment on Discussion
			{% endif %}
			{% if each_activity.3 = 'New Announcement' %}
			    New Announcement Posted
			{% endif %}
			{% if each_activity.3 = 'New Idea' %}
			    New Idea Posted
			{% endif %}			
		    </div>                                
		    <div class="nobreak clearbreak">
			{{ each_activity.1 }}
		    </div>                                
		</div>
		
	    </div>
	</div>
	{% endfor %}                    
	<div class="nobreak clearbreak activityEndLine">
	    &nbsp;
	</div>                    
    </div>
    {% else %}
	<div class="nobreak">
	    <div class="groupHomeInfoContainer">
		<div class="groupHomeInfoHeader">
		    <strong>{{group_information.info_head}}</strong>
		</div>
	    </div>
	    <div class="groupHomeInfo">
		<div class="groupHomeInfoText">
		    {{group_information.info}}
		</div>
	    </div>
	</div>
    {% endif %}
    <div class="nobreak">
	<div>
	    <div class="eventsSection">
		<div>
		    Upcoming Events
		</div>
		{% if up_group_event_list %}
		    <ul type="none">
		    {% for event in up_group_event_list %}
			    <!-- Redirect to group -->
			   <li>
				<div id="{{ event.id }}">
				    <div>
					<a href="/connectpeople/{{ group.group_web_address }}/groupevents/{{ event.id }}">{{ event.event_name }}</a>
					{{ event.event_date }}
					{% if permission == "Owner" or permission == "Board Member" or permission == "Assistant Board Member"%}
					    <a href="/connectpeople/{{ group.group_web_address }}/groupevents/edit/{{ event.id }}" eveid="{{ event.id }}" class="editEvent"><img class="eventEditIcon" title="edit" src="/{{ media_url }}/StartGroup/images/edit-icon.png"/></a>
					{% endif %}
					{% if permission == "Owner" or permission == "Board Member" %}					
					    <a href="#" eveid="{{ event.id }}" class="delEvent"><img class="eventTrashImg" title="delete" src="/{{ media_url }}/StartGroup/images/trash_icon.png"/></a>                                    
					{% endif %}
				    </div>
				    
				    <div>{{ event.event_place }}</div>
				    <div>{{ event.event_desc }}</div>
				</div>    
			   </li>
		    {% endfor %}
		    </ul>
		{% else %}
		    <div>No Upcoming Events</div>
		{% endif %}
		{% if permission == "Owner" or permission == "Board Member" or permission == "Assistant Board Member"%}
		    <div>
			<a href="/connectpeople/{{ group.group_web_address }}/groupevents/createEvent">Create New Event</a>
		    </div>
		{% endif %}
	    </div>
	    <div class="eventsSection">
		<div>
		    Previous Events
		</div>
		{% if prev_group_event_list %}
		    <ul type="none">
		    {% for event in prev_group_event_list %}
			    <!-- Redirect to group -->
			   <li>
				<div id="{{ event.id }}">
				    <div>
					<a href="/connectpeople/{{ group.group_web_address }}/groupevents/{{ event.id }}">{{ event.event_name }}</a>
					{{ event.event_date }}
					{% if permission == "Owner" or permission == "Board Member" or permission == "Assistant Board Member"  or event.post_by == userid %}
					    <a href="/connectpeople/{{ group.group_web_address }}/groupevents/edit/{{ event.id }}" eveid="{{ event.id }}" class="editEvent"><img class="eventEditIcon" title="edit" src="/{{ media_url }}/StartGroup/images/edit-icon.png"/></a>
					{% endif %}
					{% if permission == "Owner" or permission == "Board Member" or event.post_by == userid %}
					    <a href="#" eveid="{{ event.id }}" class="delEvent"><img class="eventTrashImg" title="delete" src="/{{ media_url }}/StartGroup/images/trash_icon.png"/></a>                                    
					{% endif %}
				    </div>
				    <div>{{ event.event_place }}</div>
				    <div>{{ event.event_desc }}</div>
				</div>    
			   </li>
		    {% endfor %}
		    </ul>
		{% else %}
		    <div>No Past Events</div>
		{% endif %}
	    </div>                
	<div>
	<div>
	    <div class="nobreak">
		<div class="memberSection">
		    {% if mem_grp_data %}
			Members <a href="/connectpeople/{{ group.group_web_address }}/groupMembers/">see all members</a>
			<ul type="none">
			{% for mem in mem_grp_data|slice:":5" %}
			    <!-- Redirect to group -->
			   <li>
				<div>
				    <div>
					{{ mem.photo_path|thumbnail }}
				    </div>
				    <div>{{ mem.userid|user_profile }}</div>
				</div>    
			   </li>
			{% endfor %}
			</ul>
		    {% else %}
			<div>No Members</div>
		    {% endif %}
		</div>
	    </div>
	</div>
    </div>
{% endblock %}

{% block view_poll %}

{% endblock %}

{% block create_poll %}

{% endblock %}

{% block vote %}

{% endblock %}

</body>